﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace ShoppingWebSite
{
    public class DBHelper
    {
        static string conn = "Data Source=.;Initial Catalog=ShoppingDB;Integrated Security=True";
        /// <summary>
        /// 查询方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sql,con);
            da.Fill(dt);
            return dt;
        }
        /// <summary>
        /// 增删改方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static bool GetExecuteNonQuery(string sql)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            SqlCommand com = new SqlCommand(sql, con);
            int result = com.ExecuteNonQuery();
            con.Close();
            return result > 0;
        }
    }
}